package com.itheima.springbootwebtlias.controller;


import com.aliyuncs.exceptions.ClientException;
import com.itheima.springbootwebtlias.pojo.Result;
import com.itheima.springbootwebtlias.util.AliyunOSSOperator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

//处理文件上传的处理器
@Slf4j
@RestController
public class UploadController {
    @Autowired
    private AliyunOSSOperator aliyunOSSOperator;

    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws Exception {
        log.info("文件上传，文件名：{}",file);

        String imagePath = aliyunOSSOperator.upload(file.getBytes(),file.getOriginalFilename());
        return Result.success(imagePath);
    }
}
